require(['jgGrid', 'bootstrap', 'underscore', 'jBootstrapPage'], function () {
	var webRoot = G_WEB_ROOT;
	var urls = {
		queryProductAll: webRoot + '/pc/queryProductAll',
		pcIemt: webRoot + '/pc/pcIemt'
	};

	var main = {
		init: function () {
			var classifyId = $("#classifyId").val();	// PcHomeController.pcProductListView() 主页点分类
			var brandId = $("#brandId").val();
			//			var searchTxt = $("#searchTxt").val();	// 头部传递本页
			// var transmitSearchTxt = $("#transmitSearchTxt").val(); //商品页
			console.log(classifyId);
			console.log(brandId);
			// console.log(searchTxt);
			// console.log(transmitSearchTxt);

			// $.post(urls.queryProductAll, { "pageNo": 1, "classifyId": classifyId }, function (rs) {
			// 	disposeRs(rs);
			// });
			$.post(urls.queryProductAll, { "pageNo": 1, "classifyId": classifyId }, function (rs) {
				Ks_ProductZone.render(rs.productDtos);
				createPage(12, 10, rs.totalRecords);
			});

		}
	};
	main.init();

	function createPage(pageSize, buttons, total) {
		var classifyId = $("#classifyId").val();
		$(".pagination").jBootstrapPage({
			pageSize: pageSize,
			total: total,
			maxPageButton: buttons,
			onPageClicked: function (obj, pageIndex) {
				var pn = pageIndex +1;
				$.post(urls.queryProductAll, { "pageNo": pn, "classifyId": classifyId }, function (rs) {
					$("#Ks_ProductZone").empty();
					Ks_ProductZone.render(rs.productDtos);
				});
			}
		});
	}

	/**
	 * del-kk分页
	 *
	 * @param {any} rs
	 */
	function disposeRs(rs) {
		if (null != rs) {
			Ks_ProductZone.render(rs.productDtos);
			var totalPage = 0;
			var totalRecords = 0;
			var pageNo = null;
			if (!pageNo) { pageNo = 1; }
			totalPage = rs.totalPage;
			totalRecords = rs.totalRecords;
			//生成分页
			//有些参数是可选的，比如lang，若不传有默认值
			kkpager.generPageHtml({
				mode: 'click',
				pno: pageNo,
				//总页码
				total: totalPage,
				//总数据条数
				totalRecords: totalRecords,
				//链接前部
				hrefFormer: 'pager_test',
				//链接尾部
				//		 				hrefLatter : '.html',
				click: function (n) {
					//这里可以做自已的处理
					//处理完后可以手动条用selectPage进行页码选中切换
					// $.post(urls.queryProductAll, { 'pageNo': n, 'classifyId': classifyId }, function (rs) {
					$.post(urls.queryProductAll, { 'pageNo': n }, function (rs) {
						$("#Ks_ProductZone").empty();
						console.log(rs.productDtos);
						Ks_ProductZone.render(rs.productDtos);
					});
					this.selectPage(n);
				},
			});
		}
	}
});